<?php

// $get=$_GET['id']? $_GET['id']:'';

require_once '../config.php';
require_once '../functions.php';

books_get_current_user();

function make_add()
{
    if (empty($_POST['title'])) {
        $GLOBALS['message']="请填写邮箱";
    }
    
    if (empty($_POST['number'])) {
        $GLOBALS['message']="请填写名字";
    }
    if (empty($_POST['created'])) {
        $GLOBALS['message']="请填写日期";
    }
    if (empty($_POST['ISBN'])) {
        $GLOBALS['message']="请填写日期";
    }
    if (empty($_POST['content'])) {
        $GLOBALS['message']="请填写内容";
    }

    $title= $_POST['title'];
    $number= $_POST['number'];
    $created=$_POST['created'];
    $ISBN=$_POST['ISBN'];
    $content = $_POST['content'];
    $pic = '../../static/assets/img/list/bczdnh.jpg';

    // var_dump($title);
    // $rows = book_execute("INSERT INTO list (id, title, number, synopsis, created, list_isbn) VALUES (null,'{$title}','{$number}', '{$content}', '{$created}', '{$ISBN}');");
    // var_dump($rows);
    // var_dump($title);
    $rows = book_execute("INSERT INTO list (id, title,picture, number, synopsis, created, list_isbn) VALUES (null,'{$title}','{$pic}','{$number}', '{$content}', '{$created}', '{$ISBN}');");
    // var_dump($rows);
    
    $GLOBALS['success'] = $rows > 0;
    $GLOBALS['message'] = $rows <= 0 ? '添加失败！' : '添加成功！';
}

    if ($_SERVER['REQUEST_METHOD']==='POST') {
        make_add();
    }

?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="utf-8">
  <title>Users &laquo; Admin</title>
  <link rel="stylesheet" href="/static/assets/vendors/bootstrap/css/bootstrap.css">
  <link rel="stylesheet" href="/static/assets/vendors/font-awesome/css/font-awesome.css">
  <link rel="stylesheet" href="/static/assets/vendors/nprogress/nprogress.css">
  <link rel="stylesheet" href="/static/assets/css/admin.css">
  <script src="/static/assets/vendors/nprogress/nprogress.js"></script>
</head>
<body>
  <script>NProgress.start()</script>

  <div class="main">
  
  <?php include 'inc/navbar_admin.php'; ?>
    <div class="container-fluid">
      <div class="page-title">
        <h1>创世之作</h1>
      </div>
      <?php if (isset($message)): ?>
     <?php if ($success):?>
              <!-- 有错误信息时展示 -->
      <div class="alert alert-success">
        <strong>成功！</strong><?php echo $message;?>
      </div>
    <?php else:?>
       <div class="alert alert-danger">
        <strong>错误！</strong><?php echo $message;?>
      </div>
     <?php endif ?>
     <?php endif ?>
      <div class="row">
        <div class="col-md-6">
            <form action="<?php echo $_SERVER['PHP_SELF']?>" method="post">
            <div class="form-group">
              <label for="title">标题</label>
              <input id="title" class="form-control" name="title" type="title" placeholder="标题">
            </div>
            <div class="form-group">
              <label for="number">热度</label>
              <input id="number" class="form-control" name="number" type="text" placeholder="热度">
            </div>
            <div class="form-group">
              <label for="created">日期</label>
              <input id="created" class="form-control" name="created" type="date" placeholder="日期">
            </div>
            <div class="form-group">
              <label for="ISBN">ISBN</label>
              <input id="ISBN" class="form-control" name="ISBN" type="text" placeholder="ISBN">
            </div>
            <div class="form-group">
              <label for="content">内容</label>
              <textarea class="form-control" name="content" id="content" cols="30" rows="10"></textarea>
            </div>
            <div class="form-group">
              <button class="btn btn-info" type="submit">添加</button>
              <a href="/admin/book.php" class="btn btn-info" type="submit">返回</a>
            </div>
          </form>
         
        </div>
       
      </div>
    </div>
  </div>
  <?php include 'inc/sidebar.php'; ?>
 
  <script src="/static/assets/vendors/jquery/jquery.js"></script>
  <script src="/static/assets/vendors/bootstrap/js/bootstrap.js"></script>
  <script>NProgress.done()</script>
</body>
</html>
